package com.gdssoft.pdaweb.jobs;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.util.Date;
import java.util.List;

import com.gdssoft.pdaweb.dao.PdaApplyRepairDao;
import com.gdssoft.pdaweb.model.PdaApplyRepair;
import com.gdssoft.pdaweb.service.EamService;

public class EamSyncApplyRepairJob {
private transient final Log logger = LogFactory.getLog(getClass());
	
	private EamService eamService;
	private PdaApplyRepairDao pdaApplyRepairDao;
	public EamSyncApplyRepairJob(EamService eamService,
								PdaApplyRepairDao pdaApplyRepairDao) {
		this.eamService = eamService;
		this.pdaApplyRepairDao = pdaApplyRepairDao;
	}
	
	public void doJob() {
		logger.info("EamSyncApplyRepairJob execute start");
		List<PdaApplyRepair> unSynchroPdaApplyRepairList=pdaApplyRepairDao.getApplyRepairInfo();
		for(PdaApplyRepair pdaApplyRepair : unSynchroPdaApplyRepairList){
			String wonum=null;
			logger.info("barcode : "+pdaApplyRepair.getBarCode());
			wonum = eamService.createApplyRepair(pdaApplyRepair);
			logger.info("wonum : "+wonum);
			
			if(!"".equals(wonum) && null != wonum){
				pdaApplyRepair.setIsSynchro("1");
				pdaApplyRepair.setLastEditBy("EAM");
				pdaApplyRepair.setLastEditDt(new Date());
				pdaApplyRepair.setFeedbackDt(new Date());
				pdaApplyRepair.setWoNum(wonum);/*
				pdaApplyRepair.setIsSynchro("1");
				pdaApplyRepair.setLastEditBy("EAM");
				pdaApplyRepair.setLastEditDt(new Date());
				pdaApplyRepair.setFeedbackDt(new Date());
				pdaApplyRepair.setWoNum(wonum);*/
				pdaApplyRepairDao.saveOrUpdate(pdaApplyRepair);
				/*
				PdaApplyRepair pp = pdaApplyRepairDao.get(pdaApplyRepair.getId());
				
				logger.info("-------" + pp.getWoNum());
				logger.info("success");*/
			}
		}
		logger.info("EamSyncApplyRepairJob execute end");
	}
}
